package com.cloud.wms.ui.sort.car;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Message;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;

import com.cloud.wms.R;
import com.cloud.wms.base.BaseBarActivity;
import com.cloud.wms.base.BaseFragmentActivity;
import com.cloud.wms.base.BaseViewPagerFragment;
import com.cloud.wms.config.IntentKey;
import com.cloud.wms.ui.main.entity.TaskEntity;
import com.cloud.wms.ui.sort.contract.CarSortContract;
import com.cloud.wms.ui.sort.entity.BindInfoEntity;
import com.cloud.wms.ui.sort.fragment.CarSortDetailFragment;
import com.cloud.wms.ui.sort.fragment.CarSortFragment;
import com.cloud.wms.ui.sort.presenter.CarSortPresenter;
import com.google.android.material.tabs.TabLayout;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * @Author:Chen
 * @Date: 2021-03-07 16:09
 * @Description:
 */
public class CarSortActivity extends BaseFragmentActivity<CarSortPresenter> implements CarSortContract.View {
    @BindView(R.id.tab_layout)
    TabLayout tabLayout;
    @BindView(R.id.vp_content)
    ViewPager vpContent;
    private BindInfoEntity bindInfoEntity;
    private TaskEntity taskEntity;

    @Override
    protected String barTitle() {
        return "笼车-先拣后分";
    }

    @Override
    protected int getResId() {
        return R.layout.activity_common_tab;
    }

    @Override
    protected void setupComponent() {
    }

    @Override
    protected void initEvent() {
        bindInfoEntity = getIntent().getParcelableExtra(IntentKey.OBJECT_KEY);
        taskEntity = getIntent().getParcelableExtra(IntentKey.TASK_KEY);
        super.initEvent();
    }

    @Override
    protected String[] getTabs() {
        return new String[]{"拣选中", "待拣选", "已拣选"};
    }

    @Override
    public void onSuccess(Message message) {
    }

    protected void initFragment() {
        Bundle bundle = new Bundle();
        bundle.putParcelable("SortInfoEntity", bindInfoEntity);
        bundle.putParcelable("Task", taskEntity);
        //添加tab
        for (int i = 0; i < tabs.length; i++) {
            tabLayout.addTab(tabLayout.newTab().setText(tabs[i]));
        }
        tabFragmentList.add(CarSortFragment.newInstance(bundle));
        Bundle bundleOrderDetail = new Bundle();
        bundleOrderDetail.putParcelable("SortInfoEntity", bindInfoEntity);
        bundleOrderDetail.putBoolean("IsComplete", false);
        bundleOrderDetail.putParcelable("Task", taskEntity);
        tabFragmentList.add(CarSortDetailFragment.newInstance(bundleOrderDetail));
        bundle.putBoolean("IsComplete", true);
        tabFragmentList.add(CarSortDetailFragment.newInstance(bundle));
    }

    public static void start(Context context, BindInfoEntity entity, TaskEntity taskEntity) {
        Intent intent = new Intent(context, CarSortActivity.class);
        intent.putExtra(IntentKey.OBJECT_KEY, entity);
        intent.putExtra(IntentKey.TASK_KEY, taskEntity);
        context.startActivity(intent);
    }
}
